/**
 * 	This file is part of GMGraphLib.
 * 
 * 	GMGraphLib is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  GMGraphLib is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with GMGraphLib.  If not, see <http://www.gnu.org/licenses/>.
*/
    	
package br.mendonca.gmgraphlib;

import br.mendonca.gmgraphlib.Graph;
import br.mendonca.gmgraphlib.exception.InvalidEdgeException;
import junit.framework.TestCase;

/**
 * @author Gabriel Mendonça - gabrielgmendonca@gmail.com
 *
 */
public abstract class GraphTest extends TestCase {

	protected static final int DATA_STRUCTURE = Graph.ADJACENCY_MATRIX;
	//protected static final int DATA_STRUCTURE = Graph.ADJACENCY_LIST;
	
	protected abstract String getType();
	
	protected Graph createGraph(int numberOfVertices) {
		return Graph.getInstance(getType(), numberOfVertices, DATA_STRUCTURE);
	}

	Graph graph;
	
	public void testNoVertices() {
		graph = createGraph(0);
		assertTrue(graph.getVertexList().isEmpty());
	}
	
	public void testOneVertex() {
		graph = createGraph(1);
		
		assertEquals(graph.getVertexList().get(0).index, 1);
	}
	
	public void testNoEdges() {
		graph = createGraph(0);
		assertTrue(graph.emptyEdgeList);
	}
	
	public void testInvalidEdge() {
		try {
			graph = createGraph(0);
			graph.addEdge(1, 2);
			fail("Deveria levantar uma InvalidEdgeException.");
			
		} catch (InvalidEdgeException e) {
			assertTrue(true);
		}
		
	}
	
	public void testGetNeighbors() throws Exception {
		graph = createGraph(2);
		graph.addEdge(1, 2);
		
		assertEquals(graph.getNeighbors(1).get(0).index, 2);
	}

}
